import sys

def open_file(file_path):
    """打开文件并返回内容"""
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            return file.read()
    except FileNotFoundError:
        print(f"错误: 文件 {file_path} 不存在")
        sys.exit(1)
    except Exception as e:
        print(f"打开文件时出错: {e}")
        sys.exit(1)

def count_lines(content):
    """统计文件行数"""
    return len(content.splitlines())

def count_words(content):
    """统计单词数"""
    return len(content.split())

def count_chars(content):
    """统计字符数"""
    return len(content)

def print_stats(file_path, line_count, word_count, char_count):
    """输出统计结果"""
    print(f"文件: {file_path}")
    print(f"行数: {line_count}")
    print(f"单词数: {word_count}")
    print(f"字符数: {char_count}")

if __name__ == "__main__":
    file_path = input("请输入文件路径: ")
    content = open_file(file_path)
    
    line_count = count_lines(content)
    word_count = count_words(content)
    char_count = count_chars(content)
    
    print_stats(file_path, line_count, word_count, char_count)